<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2025/6/9
  Time: 8:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js"></script>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <table border="1px" style="text-align: center">
        <tr id="tab-header">
            <th>客房名称</th>
            <th>客房价格</th>
            <th>操作</th>
        </tr>
    </table>
</body>
<script>
    roomQueryAll();
    function roomQueryAll() {
        $.ajax( {
            "url"          :  "RoomQueryAllServlet",
            "type"         :  "get",
            "data"         :  "data",
            "dataType" :  "text",
            "beforeSend": function() {
            },
            "success":  function(result) {
                var roomList=JSON.parse(result);
                var temp="";
                for (var r in roomList){
                    temp+=`
                         <tr>
                             <td>\${roomList[r].room_name}</td>
                             <td>\${roomList[r].room_price}</td>
                             <td><a href="roombuytest.jsp?roomId=\${roomList[r].room_id}">预订</a></td>
                         </tr>
                    `;
                }
                $("#tab-header").siblings().remove();
                $("#tab-header").after(temp);
            },
            "error":  function() {
                alert("网络异常")
            }
        } );
    }
</script>
</html>
